/*
	File: C:/works/3d/games/mgt/panzer_2010/data/scripts/teleporter.nut
	Author: The Team
*/

/*!
	@short	Teleporter
	@author	The Team
*/
class	Teleporter
{
	scene				=	0
	tank				=	0
	trigger_item		=	0
	layer_scale			=	0
	first_iteration		=	true

	audio				=	0

	/*!
		@short	OnUpdate
		Called during the scene update, each frame.
	*/
	function	OnUpdate(item)
	{

		if (first_iteration)
		{
			if (TriggerTestItem(ItemCastToTrigger(trigger_item), tank))
			{
				audio.PlaySfxSpawn()
				ItemSetCommandList(layer_scale, "nop 0.1;toscale 1.0, 1, 5, 1;")
				local layers = []
				layers = ItemGetChildList(ItemGetChild(layer_scale, "scaler"))
				local _layer
				foreach(_layer in layers)
					ItemSetCommandList(_layer, "toalpha 0.0, 0.5;nop 0.1; toalpha 2.0, 0.0;")
				print("Teleporter::OnUpdate() : Tank in Teleporter")
			}

			first_iteration = false
		}
	}

	/*!
		@short	OnSetup
		Called when the item is about to be setup.
	*/
	function	OnSetupDone(item)
	{
		print("Teleporter::OnSetupDone()")

		local	project_script = ProjectGetScriptInstance(g_project)
		audio = project_script.audio.player

		scene = ItemGetScene(item)
		tank = SceneFindItem(scene, "tank")
		trigger_item = ItemGetChild(item, "teleport_trigger")
		layer_scale = ItemGetChild(item, "layer_scale")
		ItemSetScale(layer_scale, Vector(1.0, 0.0, 1.0))

		print("ItemGetName = " + ItemGetName(trigger_item))
	}
}
